
/*!
 * 
 * dialog javascript
 * 
 */
$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		$( "#roleEditDialog-form" ).dialog({
			autoOpen: false,
			height: 350,
			width: 440,
			modal: true,
			buttons: {
				"是的": function() {
					alert("设置成功！");
					$("#editForm").submit(editFormCollecter());
					$( this ).dialog( "close" );
					return false;
				},
				"算了": function() {
					$( this ).dialog( "close" );
					return false;
				}
			},
			close: function() {
				$("#res").empty();
			}
		});
		
		$( ".roleEditDialog" ).click(function() {
			$( "#roleEditDialog-form" ).dialog( "open" );
			var roleId = $(this).attr("value");
			$.post("ajax/role_listRes.do", { "role.id": roleId },function(jsonData) {
				var roleList = jsonData.roleList;
				for(var i in roleList) {
					if(roleId == roleList[i].id) {
						$("#role_id").val(roleList[i].id);
						$("#role_name").val(roleList[i].name);
						$("#role_description").val(roleList[i].description);
						break;
					}
				}
				var resList = jsonData.resList;
  				var roleResList = jsonData.roleResViewList;
  				for(var i in resList) {
  					var mark = 0;
  					for(var j in roleResList) {
  						if(resList[i].id == roleResList[j].rs_id) {
  							$("#res").append("<input class='alOwn' type='checkbox' name='res_id' checked='checked' value='" + roleResList[j].id + "' />&nbsp;" + resList[i].name + "&nbsp;");
  							mark = 1;
  							break;
  						}
  					}
  					if(0 == mark)
  						$("#res").append("<input class='notOwn' type='checkbox' name='res_id' value='" + resList[i].id + "' />&nbsp;" + resList[i].name + "&nbsp;");
  					if((i+1)%3 == 0)
  						$("#res").append("<br>");
  				}
   			}, "json");	
		});
});